﻿using System;
using System.Collections.Generic;
using System.Linq;
using yiCommerce.Core.Domain.Customers;
using yiCommerce.Core.Domain.Products;
using yiCommerce.Core.Domain.Statuses;

namespace yiCommerce.Service.Statuses
{
    public class StatusMapper
    {
        public static IList<Status> ToStatusesList(IList<Status> statuses)
        {
            if (statuses == null)
            {
                return new List<Status>();
            }
            else
            {
                return statuses.Select(c => ToStatusModel(c)).ToList();
            }
        }


        public static Status ToStatusModel(Status status)
        {
            if (status == null)
            {
                return null;
            }
            else
            {
                return new Status()
                    {
                        Id = status.Id,
                        CreatedAt = status.CreatedAt,
                        Text = status.Text,
                        CustomerId = status.CustomerId,
                        Deleted = status.Deleted,

                        StatusPictures = ToStatusPictures(status.StatusPictures),
                        IsProductStatus = status.IsProductStatus,
                        Customer = new Customer()
                            {
                                Id = status.Customer.Id,
                                Username = status.Customer.Username,
                                Email = status.Customer.Email,
                                CustomerLogoId = status.Customer.CustomerLogoId,
                                CustomerLogo = status.Customer.CustomerLogo != null ? new CustomerLogo()
                                {
                                    Id = status.Customer.CustomerLogo.Id,
                                    PictureId = status.Customer.CustomerLogo.PictureId
                                } : null
                            },
                        Product = status.Product == null ? null : new Product()
                        {
                            Id = status.Product.Id,
                            ProductVariants = status.Product.ProductVariants.Select(t => new ProductVariant()
                            {
                                Id=t.Id,
                                StockQuantity = t.StockQuantity,
                                Price = t.Price
                            }).ToList()
                        }
                    };
            }
        }

        private static ICollection<StatusPicture> ToStatusPictures(ICollection<StatusPicture> statusPictures)
        {
            if (statusPictures == null)
            {
                return null;
            }
            else
            {
                return statusPictures.Select(c => new StatusPicture()
                    {
                        PictureId = c.PictureId
                    }).ToList();
            }
        }

       
    }
}